<?php
    if(!defined('BASEPATH'))
            exit('No direct script access allowed');

    function in_array_r($needle, $haystack) {
        foreach ($haystack as $item) {
            if ($item === $needle || (is_array($item) && in_array_r($needle, $item))) {
                return true;
            }
        }

        return false;
    }

    function nvlb($val, $replace){
        if( is_null($val) || $val === '' || $val == '' )  return $replace;
        else                                              return $val;
    }

    function nvl($val, $replace){
        if( is_null($val) || $val === '' )  return $replace;
        else                                return $val;
    }

    function generaOptionsCombo($valor = null, $defecto = null){
        $cadena = '<option value="">----------------</option>';
        if(is_array($valor)){
            for($i = 0; $i < count($valor); $i++){
                if($valor[$i] == $defecto){ $seleccionado = "selected"; }else{ $seleccionado = ""; }
                $cadena .= '<option value="'.$valor[$i].'" '.$seleccionado.'>'.lang($valor[$i]).'</option>';
            }
        }else{
            foreach ($valor->result_array() as $row) {
                if($row['id'] == $defecto){ $seleccionado = "selected"; }else{ $seleccionado = ""; }
                $cadena .= "<option value='".$row['id']."' ".$seleccionado.">".$row['desc']."</option>";
            }
        }
        return $cadena;
    }

    function fEnviaMailCreaUsuario($emailto = '', $subject = '', $textomail = ''){
        $this->load->library('email');

        $this->email->from('pepmanel81@gmail.com', 'Ventatron');
        $this->email->to($email);
        $this->email->subject($subject);
        $this->email->message($textomail);

        $this->email->send();
    }


?>